package com.nf.health.app.sport_recipe.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.glide.GlideUtil;
import com.nf.health.app.sport_recipe.bean.SportRecipeDetailBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by he_pan on 2017/4/18.
 * The only genius that is worth anything is the genius for hard work
 *
 * @author he_pan
 * @Description
 */

public class MovementExerciseListAdapter extends BaseAdapter {
    List<SportRecipeDetailBean.MovementBean.ListBean> mList;
    Context ctx;

    public MovementExerciseListAdapter(Context ctx, List<SportRecipeDetailBean.MovementBean.ListBean> mList) {
        this.ctx = ctx;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        if (mList != null) {
            return mList.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SportRecipeDetailBean.MovementBean.ListBean bean = mList.get(position);
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(ctx).inflate(R.layout.item_movement_exercise, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GlideUtil.loadNetImg(ctx, holder.ivHimg, bean.getHimg(), R.drawable.default_image);
        holder.tvName.setText(bean.getName());
        holder.tvContent.setText(bean.getContent());
        holder.tvActionfrequencyActionintension.setText(bean.getActionfrequency() + "  " + bean.getActionintension());
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.iv_himg)
        ImageView ivHimg;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_actionfrequency_actionintension)
        TextView tvActionfrequencyActionintension;
        @Bind(R.id.tv_content)
        TextView tvContent;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
